<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActionController::Routing::Optimisation::PositionalArguments</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActionController::Routing::Optimisation::PositionalArguments</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/actionpack/lib/action_controller/routing_optimisation_rb.html">
                vendor/rails/actionpack/lib/action_controller/routing_optimisation.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Optimiser.html">
                Optimiser
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Given a route: map.person &#8217;/people/:id&#8216;
</p>
<p>
If the user calls person_url(@person), we can simply return a string like
&quot;/people/#{@person.to_param}&quot; rather than triggering the
expensive logic in url_for
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000340">generation_code</a>&nbsp;&nbsp;
      <a href="#M000339">guard_condition</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000340" class="method-detail">
        <a name="M000340"></a>

        <div class="method-heading">
          <a href="#M000340" class="method-signature">
          <span class="method-name">generation_code</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000340-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000340-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/routing_optimisation.rb, line 69</span>
69:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generation_code</span>
70:           <span class="ruby-identifier">elements</span> = []
71:           <span class="ruby-identifier">idx</span> = <span class="ruby-value">0</span>
72: 
73:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">kind</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:url</span>
74:             <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'#{request.protocol}'</span>
75:             <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'#{request.host_with_port}'</span>
76:           <span class="ruby-keyword kw">end</span>
77: 
78:           <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'#{request.relative_url_root if request.relative_url_root}'</span>
79: 
80:           <span class="ruby-comment cmt"># The last entry in route.segments appears to # *always* be a</span>
81:           <span class="ruby-comment cmt"># 'divider segment' for '/' but we have assertions to ensure that</span>
82:           <span class="ruby-comment cmt"># we don't include the trailing slashes, so skip them.</span>
83:           (<span class="ruby-identifier">route</span>.<span class="ruby-identifier">segments</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">segments</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">route</span>.<span class="ruby-identifier">segments</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">segment</span><span class="ruby-operator">|</span>
84:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">segment</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">DynamicSegment</span>)
85:               <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">segment</span>.<span class="ruby-identifier">interpolation_chunk</span>(<span class="ruby-node">&quot;args[#{idx}].to_param&quot;</span>)
86:               <span class="ruby-identifier">idx</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
87:             <span class="ruby-keyword kw">else</span>
88:               <span class="ruby-identifier">elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">segment</span>.<span class="ruby-identifier">interpolation_chunk</span>
89:             <span class="ruby-keyword kw">end</span>
90:           <span class="ruby-keyword kw">end</span>
91:           <span class="ruby-node">%(&quot;#{elements * ''}&quot;)</span>
92:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000339" class="method-detail">
        <a name="M000339"></a>

        <div class="method-heading">
          <a href="#M000339" class="method-signature">
          <span class="method-name">guard_condition</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000339-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000339-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/routing_optimisation.rb, line 58</span>
58:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">guard_condition</span>
59:           <span class="ruby-identifier">number_of_arguments</span> = <span class="ruby-identifier">route</span>.<span class="ruby-identifier">segment_keys</span>.<span class="ruby-identifier">size</span>
60:           <span class="ruby-comment cmt"># if they're using foo_url(:id=&gt;2) it's one </span>
61:           <span class="ruby-comment cmt"># argument, but we don't want to generate /foos/id2</span>
62:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">number_of_arguments</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
63:             <span class="ruby-value str">&quot;defined?(request) &amp;&amp; request &amp;&amp; args.size == 1 &amp;&amp; !args.first.is_a?(Hash)&quot;</span>
64:           <span class="ruby-keyword kw">else</span>
65:             <span class="ruby-node">&quot;defined?(request) &amp;&amp; request &amp;&amp; args.size == #{number_of_arguments}&quot;</span>
66:           <span class="ruby-keyword kw">end</span>
67:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>